home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_dev.lha / GMSDev / Source / E / Demos / MultiLine.e < prev    next >
Encoding:
Text File  |  1998-10-22  |  3.9 KB  |  152 lines

  1. /* GMS-example
  2. **
  3. ** Name:    MultiLine.e
  4. ** Type:    Blitter example (based on Bounceline.e/c)
  5. ** Version: 1.1
  6. ** Author:  G. W. Thomassen (0000272e@lts.mil.no)
  7. */
  8.  
  9. MODULE 'gms/dpkernel','gms/dpkernel/dpkernel','gms/graphics/pictures',
  10.        'gms/screens','gms/system/register','gms/system/modules','gms/graphics/pictures',
  11.        'gms/graphics/screens','gms/graphics/blitter','gms/blitter'
  12.  
  13. ENUM NONE,ERR_LIB,ERR_SCR,ERR_SMOD,ERR_BMOD,ERR_JOY
  14.  
  15. PROC main() HANDLE
  16.   DEF scr=NIL:PTR TO screen,
  17.       scrmodule=NIL:PTR TO module,
  18.       bltmodule=NIL:PTR TO module,
  19.       sx,sy,ex,ey,state,up=0,
  20.       dsx,dsy,dex,dey,col,count=0
  21.  
  22.   DEF colours[10]:ARRAY OF LONG
  23.  
  24.   colours := [ $00ff0000, $0000ff00, $000000ff, $00ff00ff, $0000ff77,
  25.                $00ffff00, $004488aa, $0000ffff, $00999999, $00ffffff ]:LONG
  26.  
  27.  
  28.   IF (dpkbase:=OpenLibrary('GMS:libs/dpkernel.library',0))=NIL THEN Raise(ERR_LIB)
  29.  
  30.   IF (bltmodule:=Init([TAGS_MODULE,NIL,     ->blitter-module
  31.       MODA_NUMBER,    MOD_BLITTER,
  32.       MODA_TABLETYPE, JMP_AMIGAE,
  33.       TAGEND], NIL))=NIL THEN Raise(ERR_BMOD)
  34.       bltbase := bltmodule.modbase
  35.  
  36.   IF (scrmodule:=Init([TAGS_MODULE,NIL,       ->screen-module
  37.       MODA_NUMBER,    MOD_SCREENS,
  38.       MODA_TABLETYPE, JMP_AMIGAE,
  39.       TAGEND], NIL))=NIL THEN Raise(ERR_SMOD)
  40.       scrbase:=scrmodule.modbase
  41.  
  42.   col := colours[SlowRandom(10)] -> Set the first colour.
  43.  
  44.   IF (scr:=Init([TAGS_SCREEN, NIL,
  45.        GSA_ScrMode, SM_HIRES + SM_LACED,
  46.        GSA_Width,   640,
  47.        GSA_Height,  512,
  48.        GSA_Attrib,  SCR_DBLBUFFER,   -> Two frames (Doublebuffering)
  49.          GSA_BitmapTags, NIL,
  50.          BMA_Palette,    [PALETTE_ARRAY,2,$000000,$000000],
  51.          TAGEND,NIL,
  52.        TAGEND],NIL))=NIL THEN Raise(ERR_SCR)
  53.  
  54.   -> Calculate start values..
  55.   sx:=SlowRandom(scr.width);  dsx:=-1
  56.   sy:=SlowRandom(scr.height); dsy:=2
  57.   ex:=SlowRandom(scr.width);  dex:=3
  58.   ey:=SlowRandom(scr.height); dey:=1
  59.  
  60.   -> Display the screen
  61.   Show(scr)
  62.  
  63.   REPEAT
  64.     /* Calculate new values */
  65.     sx:=sx+dsx
  66.     sy:=sy+dsy
  67.     ex:=ex+dex
  68.     ey:=ey+dey
  69.  
  70.     /* Check if screen limits are exceeded */
  71.     IF sx<0; sx:=0; dsx:=-dsx; ENDIF
  72.     IF sy<0; sy:=0; dsy:=-dsy; ENDIF
  73.     IF ex<0; ex:=0; dex:=-dex; ENDIF
  74.     IF ey<0; ey:=0; dey:=-dey; ENDIF
  75.  
  76.     IF (sx>(scr.width))
  77.       sx  := scr.width-2
  78.       dsx := -dsx
  79.     ENDIF
  80.     IF (sy>(scr.height))
  81.       sy  := scr.height-2
  82.       dsy := -dsy
  83.     ENDIF
  84.     IF (ex>(scr.width))
  85.       ex  := scr.width-2
  86.       dex := -dex
  87.     ENDIF
  88.     IF (ey>(scr.height))
  89.       ey  :=scr.height-2
  90.       dey :=-dey
  91.     ENDIF
  92.  
  93.     /* Fading */
  94.  
  95.     IF (up=0)
  96.        /* Fade from black into a colour */
  97.        state := ColourMorph(scr,state,3,1,1,$000000,col)
  98.        IF (state = NIL)
  99.           up := 1
  100.           count := NIL
  101.        ENDIF
  102.     ELSEIF (up=1)
  103.        count := count + 1
  104.        IF (count > 700)
  105.           count := NIL
  106.           up    := 2
  107.        ENDIF
  108.     ELSEIF (up=2)
  109.        /* Fade from colour down to black */
  110.  
  111.        state := ColourMorph(scr,state,1,1,1,col,$000000)
  112.  
  113.        IF (state = NIL)
  114.           Clear(scr.bitmap); WaitAVBL()
  115.           SwapBuffers(scr);  WaitAVBL()
  116.           Clear(scr.bitmap)
  117.           col := colours[SlowRandom(10)]
  118.           up  := 0 /* Fade back into a colour next time */
  119.        ENDIF
  120.     ENDIF
  121.  
  122.     /* Drawing */
  123.  
  124.     -> Draw the line and put the frame in front.
  125.     DrawLine(scr.bitmap,sx,sy,ex,ey,1,$FFFFFFFF)
  126.     WaitAVBL()
  127.     SwapBuffers(scr)
  128.   UNTIL Mouse()=1       -> You should use the Joy-module instead.
  129.  
  130.   -> No error..
  131.   Raise(NONE)
  132.  
  133. EXCEPT DO
  134.  
  135.   -> Close down everything
  136.   IF scr THEN Free(scr)
  137.   IF scrmodule THEN Free(scrmodule)
  138.   IF bltmodule THEN Free(bltmodule)
  139.   CloseDPK()
  140.  
  141.   -> Report errors..
  142.   SELECT exception
  143.   CASE ERR_LIB; WriteF('Couldn\at open "dpkernel.library"\n')
  144.   CASE ERR_SMOD; WriteF('Couldn\at initialize screen-module\n')
  145.   CASE ERR_SCR; WriteF('Couldn\at open screen\n')
  146.   CASE ERR_BMOD; WriteF('Couldn\at initialize blitter-module\n')
  147.   ENDSELECT
  148.  
  149.   -> End with the return code 0, a good way to end programs..
  150.   CleanUp(0)
  151. ENDPROC
  152.